<%@page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>新建用户</title>
<script type="text/javascript" src="/daycodefront/lib/extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="/daycodefront/lib/extjs/ext-all-debug.js"></script>
<script type="text/javascript" src="/daycodefront/lib/extjs/src/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="/daycodefront/common/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="msgBox.js"></script>
<script type="text/javascript">
	/**确定按钮**/
	function addUser() {
		var usernameValue = document.getElementById("username").value;
		var realNameValue = document.getElementById("realName").value;
		var passwordValue = document.getElementById("password").value;
		var rePasswordValue = document.getElementById("rePassword").value;
		var birthdayValue = document.getElementById("birthday").value;
		var emailValue = document.getElementById("email").value;
		var sexValue = document.getElementById("sex").value;
		var isActivatedValue = document.getElementById("isActivated").value;
		var groupValue = document.getElementById("group").value;
		var notesValue = document.getElementById("notes").value;
		var passwordFormat = "[a-zA-Z0-9]{6,18}$";
		var usernameFormat = "\\w{4,20}$";
		var emailFormat = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
			if(usernameValue==""){
				alert("用户名不能为空！");
				return false;
			}else if(passwordValue=="") {
				alert("密码不能为空！");
				return false;
			}else if(emailValue=="") {
				alert("邮箱不能为空！");
				return false;
			}
			if(!usernameValue.match(usernameFormat)){
				alert("用户名格式由5-20位字母或数字组成");
				return false;
			}else if(!passwordValue.match(passwordFormat)) {
				alert("密码为6-18位的字母或数字组成！");
				return false;
			}else if (passwordValue != rePasswordValue) {
				alert("两次密码输入不一样！");
				return false;
			}else if(!emailValue.match(emailFormat)) {
				alert("邮箱格式不正确！");
				return false;
			}
			Ext.Ajax.request({
				url : "addUser.action",
				method : 'POST',
				params : {
					"userVOBean.username" : usernameValue,
					"userVOBean.realName" : realNameValue,
					"userVOBean.password" : passwordValue,
					"userVOBean.sex" : sexValue,
					"userVOBean.birthday" : birthdayValue,
					"userVOBean.email" : emailValue,
					"userVOBean.isActivated" : isActivatedValue,
					"groupValue" : groupValue,
					"userVOBean.notes" : notesValue
				},
				success : function(response, options) {
					var res = Ext.util.JSON.decode(response.responseText);
					if (res.success) {// 判断请求是否成功
						window.parent.frames.refresh();
						window.parent.frames.msgBox_close();
					} else {
						if(res.msg=="email"){
							alert("此注册邮箱已被注册过！");
						}else if(res.msg=="username"){
							alert("存在同名用户！");
						}
					}
				},
				failure : function(response, options) {
				}
			});
	}
</script>
<style type="text/css">
* { margin: 0px; padding: 0px; }
table { font: 14px 'Microsoft YaHei', '微软雅黑'; }
table tr { height: 40px; }
table tr td input { height: 23px; }
.title { text-align:right;  }
.birthday img:HOVER{ cursor:pointer;}
.notes{ width:600px;height:100px;overflow-x:visible;overflow-y:visible}
</style>
</head>
<body>
	<div class="content">
		<form action="addUser" name="addUserForm">
			<table width="100%" border="0">
				<tr>
					<td width="20%" class="title">用户名：</td>
					<td><input type="text" id="username" name="userVOBean.username" style="width:200px;" /></td>
					<td width="23%" class="title">真实姓名：</td>
					<td><input type="text" id="realName" name="userVOBean.realName"  style="width:200px;"/></td>
				</tr>
				<tr>
					<td width="20%" class="title">设置密码：</td>
					<td><input type="password" id="password" name="userVOBean.password" style="width:200px;" /></td>
					<td width="23%" class="title">确认密码：</td>
					<td><input type="password" id="rePassword" name="rePassword"  style="width:200px;"/></td>
				</tr>
				<tr>
					<td class="title">性别：</td>
					<td><select id="sex" style="width: 50px;" >
							<option value=""></option>
							<option value="男">男</option>
							<option value="女">女</option>
					</select>
					</td>
					<td class="title">出生年月：</td>
					<td class="birthday"><input id="birthday" type="text" name="userVOBean.birthday" style="width:180px;" onfocus="WdatePicker();"
						readonly="readonly" />
						<img onclick="WdatePicker({el:'birthday'})" src="/daycodefront/common/My97DatePicker/skin/datePicker.gif" 
						 width="16" height="22" align="absmiddle"/>
					</td>
				</tr>
				</tr>
				<tr>
					<td class="title">注册邮箱：</td>
					<td><input type="text" id="email" name="userVOBean.email"  style="width:200px;"/></td>
					<td class="title">是否激活：</td>
					<td><select id="isActivated" style="width: 50px;" >
							<option value=""></option>
							<option value="1">是</option>
							<option value="0">否</option>
					</select>
				</tr>
				<tr>
					<td class="title">所在用户组：</td>
					<td colspan="4"><select id="group" style="width: 200px;" >
							<option value="1">入门级程序员</option>
							<option value="2">中级程序员</option>
							<option value="3">高级程序员</option>
					</select>
					</td>
				</tr>
				<tr>
					<td class="title">备注：</td>
					<td colspan="4"><textarea type="text" id="notes" class="notes" name="userVOBean.notes"
							value=""></textarea>
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>
